print(5*'*'+'nonlocal关键字用来在函数或其他作用域中使用外层(非全局)变量'+5*'*')


def make_counter():
    count = 0
    def counter():
        nonlocal count
        count +=1
        return count
    return counter

def make_counter_test():
    mc = make_counter()
    print(mc())
    print(mc())
    print(mc())

make_counter_test()

# 闭包
def conter():
    c = [0]
    def inc():
        c[0] += 1
        return c[0]
    return inc

foo = conter()
print(foo(),foo())
c = 100
print(foo())

